﻿namespace StackDeck.Data
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using StackDeck.Model;

    using User = StackDeck.Model.User;

    public class StackOverflowRepository : IStackOverflowRepository
    {
        private const string Url = "https://odata.sqlazurelabs.com/OData.svc/v0.1/rp1uiewita/StackOverflow";

        public IEnumerable<User> GetTopUsers(int max)
        {            
            var context = new StackOverflow.StackOverflow(new Uri(Url));
            var users = context.Users.OrderByDescending(u => u.Reputation).Take(max).Select(u => new User {DisplayName = u.DisplayName, Reputation = u.Reputation });
            return users;
        }
    }
}